using System;
using System.Collections.Generic;
using System.Text;
using System.DirectoryServices;
using System.Configuration;

namespace Suucha.Adsi
{
    public sealed class AdsiCommon
    {
        
        private AdsiCommon()
        {
        }

        public static DirectoryEntry GetDirectoryEntry(string adPath, string userName, string password)
        {
            DirectoryEntry de = new DirectoryEntry(adPath, userName, password, AuthenticationTypes.Secure);
            return de;
        }

        public static DirectoryEntry GetDirectoryEntry(string path)
        {
            DirectoryEntry de = new DirectoryEntry(path);
            return de;
        }

        public static DirectorySearcher GetDirectorySearcher(string path, string userName, string password)
        {
            DirectoryEntry de = new DirectoryEntry(path, userName, password);
            return new DirectorySearcher(de);
        }

        public static DirectorySearcher GetDirectorySearcher(DirectoryEntry de)
        {
            DirectorySearcher ds = new DirectorySearcher(de);
            return ds;
        }

        public static void DeleteDirectoryEntry(string path, string userName, string password)
        {
            DirectoryEntry de = AdsiCommon.GetDirectoryEntry(path, userName, password);
            DirectoryEntry parent = de.Parent;
            parent.Children.Remove(de);
            parent.CommitChanges();
        }
    }
}
